home *** CD-ROM | disk | FTP | other *** search
- Path: sable.ox.ac.uk!mert0053
- From: mert0053@sable.ox.ac.uk (Michael Brewer)
- Newsgroups: comp.lang.c++
- Subject: Deleting arrays of garbage collectables
- Date: 10 Jan 1996 15:35:11 GMT
- Organization: Oxford University, England
- Message-ID: <4d0mbf$6on@news.ox.ac.uk>
- NNTP-Posting-Host: sable.ox.ac.uk
- X-Newsreader: TIN [version 1.2 PL2]
-
- Probably a bad subject line, but here is what I mean:
-
- I am using a bunch of classes that can be shared by the mechanism:
-
- class Allo; // defined elsewhere
-
- Allo *hi = new Allo;
- hi->ref(); // Using this object
- //..... code
- hi->unref(); // finished with it. If it hasn't been ref()'ed
- // elsewhere, it will be deleted
-
-
- Now what if I want an array of these? There is no satisfactory default
- constructor, so I need an array of pointers:
-
- Allo **arr = new Allo * [10];
- for(int i = 0; i < 10; i++)
- {
- arr[i] = new Allo(3.221);
- arr[i]->ref();
- }
- // ......... code
- // ....
- // finished, unref():
- for(int i = 0; i < 10; i++)
- arr[i]->unref();
-
-
- OK, so now the arr[i] memory has been dealt with, but what about the
- array of pointers arr?? There is no way of telling whether they still
- point to something, since some other object may still be sharing the
- data.
-
- Is there a way to free up that memory?
-
- Thanks.
-
- Mike
-